package keeto.com.vn.classified.adapter;

import java.util.Vector;

import keeto.com.vn.classfied.model.Category;
import keeto.com.vn.classified.common.ICategoriesProductsAdapter;
import android.content.Context;
import android.widget.BaseAdapter;

public enum ProductCategoriesAdapterManager {

	INSTANCE;
	private Context context;
	private Vector<?> dataSource;
	private String currentAction;

	
	public static final int ADAPTER_CATEGORY = 0;
	public static final int ADAPTER_SUB_CATEGORY = 1;
	private BaseAdapter adapter = null;
	
	private ProductCategoriesAdapterManager() {
	}

	public static ProductCategoriesAdapterManager getInstance(Context context,
			Vector<?> dataSource, String currentAction) {
		INSTANCE.context = context;
		INSTANCE.dataSource = dataSource;
		INSTANCE.currentAction = currentAction;
		return INSTANCE;
	}
	
	
	private ICategoriesProductsAdapter currentAdapter = null;
	
	
	@SuppressWarnings("unchecked")
	public BaseAdapter getAdapterByType(int type) {
		switch (type) {
		case ADAPTER_CATEGORY:
			adapter = new CategoriesAdapter((Vector<Category>) dataSource, context, currentAction);
			currentAdapter = (ICategoriesProductsAdapter) adapter;
			break;
		case ADAPTER_SUB_CATEGORY:
			adapter = new SubCategoryAdapter((Vector<Category>) dataSource, currentAction, context);
			currentAdapter = (ICategoriesProductsAdapter)adapter;
			break;
		}
		return adapter;
	}
	public void notifyDataChanged(Vector<?> dataSource){
		this.dataSource = dataSource;
		currentAdapter.setDataSource(dataSource);
		adapter.notifyDataSetChanged();
	}
}
